public class Solution622 {

    int[] queue;
    int size;
    int l,r;

    public Solution622(int k) {
        queue=new int[k];
        size=0;
        l=0;
        r=-1;
    }

    public boolean enQueue(int value) {
        if (isFull()){
            return false;
        }
        size++;
        r=(r+1)%queue.length;
        queue[r]=value;
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()){
            return false;
        }
        size--;
        l=(l+1)%queue.length;
        return true;
    }

    public int Front() {
        if (isEmpty()){
            return -1;
        }
        return queue[l];
    }

    public int Rear() {
        if (isEmpty()){
            return -1;
        }
        return queue[r];
    }

    public boolean isEmpty() {
        return size==0;
    }

    public boolean isFull() {
        return size==queue.length;
    }

    public static void main(String[] args) {
        Solution622 solution622=new Solution622(3);
        System.out.println(solution622.enQueue(1));
        System.out.println(solution622.enQueue(2));
        System.out.println(solution622.enQueue(3));
        System.out.println(solution622.enQueue(4));
        System.out.println(solution622.Rear());
        System.out.println(solution622.isFull());
        System.out.println(solution622.deQueue());
        System.out.println(solution622.enQueue(4));
        System.out.println(solution622.Rear());
    }
}
